package com.astar.config;

import org.simplejavamail.mailer.Mailer;
import org.simplejavamail.mailer.MailerBuilder;
import org.simplejavamail.mailer.config.TransportStrategy;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Created by liuruiyan on 2018/10/28.
 */
@Configuration
public class EmailConfig {

    @Value("${mail.server.host:''}")
    private String host;

    @Value("${mail.server.port:''}")
    private Integer port;


    @Value("${mail.server.username:''}")
    private String username;

    @Value("${mail.server.password:''}")
    private String password;



    @Bean
    public Mailer initMailer() {
        return  MailerBuilder
                .withSMTPServer(host,port,username,password)
                .withTransportStrategy(TransportStrategy.SMTPS)
                .buildMailer();
    }

}
